<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<input type="text" placeholder="请输入1-100的数字;" id="d1">
<input type="button" value="猜一猜" onclick="f()">
<div></div>


<script>

    /*
        let x = parseInt(Math.random() * 100) + 1;
        let count = 0;
            function f() {
            count++;
            let i = document.querySelector("#d1");
            let d = document.querySelector("div");


            if (i.value > x){
                d.innerText = "猜大了";
            }else if (i.value < x){
                d.innerText = "猜小了";
            }else{
                d.innerText = "恭喜你,猜对了"+count+"次猜对了";
            }
        }
    */
    let x = parseInt(Math.random() * 100) + 1;
    let count = 0;
        function f(){
            count++;
            let i = document.querySelector("#d1");
            let d = document.querySelector("div");

            if (i.value >x){
                d.innerText = "猜大了~";
            }else if (i.value < x){
                d.innerTexr = "猜小了!";
            }else{
                d.innerTexr = "恭喜你,猜对了"+count+"次";
            }
        }

</script>
</body>
</html>